package com.itcast.donkey.fragments;

import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.itcast.donkey.R;
import com.itcast.donkey.adapters.SeachAbroadAdapter;
import com.itcast.donkey.utils.AssetsDatabaseManager;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

/**
 * Created by lanouhn on 16/8/26.
 */
public class AbroadFragment extends Fragment {
    private RecyclerView recyclerView;
    private SeachAbroadAdapter adapter;

    private String[] entryName = {"日本", "泰国", "美国", "韩国", "法国", "马来西亚", "意大利", "英国", "德国", "新加坡", "澳大利亚", "柬埔寨", "瑞士", "越南",
            "西班牙", "印度尼西亚", "奥地利", "土耳其", "新西兰", "菲律宾", "斯里兰卡", "阿联酋", "俄罗斯", "马尔代夫", "捷克", "加拿大", "荷兰", "希腊", "尼泊尔",
            "比利时", "印度", "摩纳哥", "新目的地", "匈牙利", "芬兰", "瑞典", "丹麦", "挪威", "埃及", "葡萄牙", "缅甸", "卡塔尔", "南非", "老挝", "墨西哥", "毛里求斯",
            "列支敦士登", "冰岛", "伊朗", "卢森堡", "以色列", "肯尼亚", "斯洛伐克", "爱尔兰", "波兰", "帕劳", "约旦", "朝鲜", "巴西", "斐济", "克罗地亚", "塞舌尔",
            "爱沙尼亚", "摩洛哥", "波多黎各", "秘鲁", "突尼斯", "斯洛文尼亚", "古巴", "阿根廷", "马耳他", "智利", "不丹", "波黑共和国", "巴基斯坦", "马其顿共和国",
            "塞尔维亚", "立陶宛", "黑山共和国", "塞浦路斯", "保加利亚", "南极", "文莱", "马达加斯加", "哈萨克斯坦", "坦桑尼亚", "哥斯达黎加", "孟加拉国", "蒙古国",
            "委内瑞拉", "罗马尼亚", "白俄罗斯", "布隆迪", "巴林", "阿曼", "吉布提", "沙特阿拉伯"};

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_abroad, null);
        return view;
    }


    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        recyclerView = (RecyclerView) getView().findViewById(R.id.recyclerView_abroad);

        GridLayoutManager gm = new GridLayoutManager(getActivity(), 3);
        gm.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(gm);

        adapter = new SeachAbroadAdapter(getActivity(), entryName);
        recyclerView.setAdapter(adapter);

//        // 初始化，只需要调用一次
//        AssetsDatabaseManager.initManager(getActivity().getApplication());
//        // 获取管理对象，因为数据库需要通过管理对象才能够获取
//        AssetsDatabaseManager mg = AssetsDatabaseManager.getManager();
//        // 通过管理对象获取数据库
//        SQLiteDatabase db1 = mg.getDatabase("db1.db");
//        // 对数据库进行操作
//        db1.execSQL("insert into tb([ID],[content]) values(null, 'db1');");
    }
}
